﻿
@using IOA.MES.DataAccess.Enum
@{
    ViewBag.Title = "质量报表";
    Layout = "~/Views/Shared/_LayoutPage.cshtml";
    var workshops = ViewBag.Workshops as List<IOA.MES.DataAccess.VModel.VWorkshop>;
    var startTime = DateTime.Now.TimeOfDay < new TimeSpan(8, 0, 0) ? DateTime.Today.AddDays(-1).AddHours(20) : (DateTime.Now.TimeOfDay < new TimeSpan(20, 0, 0) ? DateTime.Today.AddHours(8) : DateTime.Today.AddHours(20));
    var endTime = DateTime.Now.TimeOfDay < new TimeSpan(8, 0, 0) ? DateTime.Today.AddHours(8) : (DateTime.Now.TimeOfDay < new TimeSpan(20, 0, 0) ? DateTime.Today.AddHours(20) : DateTime.Today.AddDays(1).AddHours(8));
}
@section Contents{
    <style>
        .layui-form-label {
            width: auto;
        }
    </style>
}

<div id="page"></div>

<script type="text/template" id="tplPage">
    <div class="layui-fluid">
        <div class="layui-card">
            <div class="layui-form layui-card-header layuiadmin-card-header-auto">
                <div class="layui-form-item">
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.WorkShop">车间：</label>
                        <div class="layui-input-inline">
                            <select id="selWorkshops" lay-filter="selWorkshops">
                                @foreach (var item in workshops)
                                {
                                    <option value="@item.WorkshopCode" @(workshops.IndexOf(item) == 0 ? " selected " : "")>@item.WorkshopName</option>
                                }
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" name="lineId" v-html="lang.Field.AssemblyLine">流水线：</label>
                        <div class="layui-input-inline">
                            <select id="selLines" lay-filter="selLines">
                                <option value="0">全部</option>
                            </select>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <label class="layui-form-label" v-html="lang.Field.ProduceTime">生产时间：</label>
                        <div class="layui-input-inline" style="width:440px;">
                            <input type="text" id="txtRangeTime" style="width:310px;float:left;" value="@(startTime.ToString("yyyy-MM-dd HH:mm:ss") + " 至 " + endTime.ToString("yyyy-MM-dd HH:mm:ss"))" autocomplete="off" class="layui-input">
                            <button class="layui-btn layuiadmin-btn-list layui-bg-cyan btnPreDuty" type="button" style="margin-top:-6px;">
                                <i class="layui-icon layui-icon-prev layuiadmin-button-btn"></i>
                            </button>
                            <button class="layui-btn layuiadmin-btn-list layui-bg-cyan btnNextDuty" type="button" style="margin-top:-6px;margin-left:0;">
                                <i class="layui-icon layui-icon-next layuiadmin-button-btn"></i>
                            </button>
                        </div>
                    </div>
                    <div class="layui-inline">
                        <button id="btnSearch" class="layui-btn layuiadmin-btn-list" style="margin-top:-6px;" type="button">
                            <i class="layui-icon layui-icon-search layuiadmin-button-btn"></i>
                        </button>
                        <a id="btnExport" target="_blank" class="layui-btn layuiadmin-btn-list" style="margin-top:-6px;" href="javascript:void(0)">
                            <i class="layui-icon layui-icon-download-circle layuiadmin-button-btn"></i>
                        </a>
                    </div>
                </div>
            </div>
        </div>

        <div class="layui-card">
            <div class="layui-card-body">
                <table id="table" lay-filter="table"></table>
            </div>
        </div>
    </div>
</script>

@section Scripts{
    <script src="/res/echarts/echarts.min.js"></script>
    <script src="/res/echarts/macarons.js"></script>
    <script>
        var vm = new Vue({
            el: "#page",
            template: "#tplPage",
            data: {
                lang: JSON.parse(lang).package
            }
        });
        setTimeout(function () {
            initLayui();
        }, 50);

        function initLayui() {
            layui.use(['table', 'layer', 'form', 'laydate', 'element'], function () {
                var layer = layui.layer,
                    table = layui.table,
                    form = layui.form,
                    laydate = layui.laydate;
                laydate.render({
                    elem: '.rangetime'
                    , type: 'datetime'
                    , range: '至'
                });

                form.on("select(selWorkshops)", function (data) {
                    queryLines();
                });
                queryLines();
                function queryLines() {
                    var loadId = layui.layer.load();
                    $.ajax({
                        url: "/Report/QueryLines",
                        data: {
                            workshopCode: $("#selWorkshops").val().trim()
                        },
                        complete: function () {
                            layui.layer.close(loadId);
                        },
                        success: function (res) {
                            if (res.ErrCode != 200) {
                                layui.layer.msg(res.ErrMsg, { icon: 5 });
                                return;
                            }
                            var html = ["<option value='0'>全部</option>"];
                            for (var i = 0; i < res.Data.length; i++) {
                                html.push("<option value='" + res.Data[i].PkId + "'>" + res.Data[i].LineName + "</option>");
                            }
                            $("#selLines").html(html.join(""));
                            form.render("select");
                        }
                    });
                }

                var options = {
                    elem: '#table'
                    , url: '/Report/QueryQualityReports'
                    , method: "post"
                    , where: { workshopCode: "", lineId: 0, startTime: "", endTime: "" }
                    , page: {
                        limit: 15
                        , limits: [15, 20, 25, 30, 40, 50]
                    }
                    , response: {
                        statusName: 'ErrCode'
                        , statusCode: 200
                        , msgName: 'ErrCode'
                        , countName: 'TotalCount'
                        , dataName: 'Data'
                    }
                    , cols: [[
                        { title: 'ID', type: "numbers", width: 60, fixed: "left" }
                        , { field: 'BarCode', title: '条码', minWidth: 200, fixed: "left" }
                        , { field: 'CellCompany', title: '电池厂商', minWidth: 100 }
                        , { field: 'Efficiency', title: '效率', minWidth: 100 }
                        , { field: 'SinglePower', title: '单片功率', minWidth: 100 }
                        , { field: 'TheoreticalPower', title: '理论功率', minWidth: 100 }
                        , { field: 'Voc', title: 'Voc', minWidth: 100 }
                        , { field: 'Isc', title: 'Isc', minWidth: 100 }
                        , { field: 'Vm', title: 'Vm', minWidth: 100 }
                        , { field: 'Im', title: 'Im', minWidth: 100 }
                        , { field: 'FF', title: 'FF', minWidth: 100 }
                        , { field: 'Pmax', title: 'Pmax', minWidth: 100 }
                        , { field: 'CTM', title: 'CTM', minWidth: 100 }
                        , { field: 'RatedPower', title: '额定功率', minWidth: 100 }
                        , { field: 'OrderNo', title: '订单号', minWidth: 100 }
                        , { field: 'WorkOrderNo', title: '工单号', minWidth: 100 }
                        , { field: 'CellLevel', title: '电池等级', minWidth: 100 }
                        , { field: 'CellModel', title: '电池型号', minWidth: 100 }
                        , { field: 'CellColor', title: '电池颜色', minWidth: 100 }
                        , { field: 'WeldingMachine', title: '焊接机', minWidth: 100 }
                        , { field: 'CellPiece', title: '电池片数', minWidth: 100 }
                        , { field: 'Schema', title: '方案', minWidth: 100 }
                        , { field: 'Temp', title: '温度', minWidth: 100 }
                        , { field: 'ConversionEfficiency', title: '转换效率', minWidth: 100 }
                        , { field: 'LightIntensity', title: '光强', minWidth: 100 }
                        , { field: 'SeriesResistance', title: '串阻', minWidth: 100 }
                        , { field: 'ParallelResistance', title: '并阻', minWidth: 100 }
                        , { field: 'PackagingLoss', title: '封装损耗', minWidth: 100 }
                        , { field: 'CurrentLevel', title: '档位', minWidth: 100 }
                        , { field: 'PackNo', title: '打包编号', minWidth: 150 }
                        , { field: 'PackTimeStr', title: '打包时间', minWidth: 150 }
                        , { field: 'Operator', title: '操作员', minWidth: 100 }
                        , { field: 'Duty', title: '班次', minWidth: 100 }
                        , { field: 'TimeStr', title: '时间', minWidth: 150 }
                    ]]
                };

                $("#btnSearch").click(function () {
                    queryTable();
                });
                queryTable();
                function queryTable() {
                    options.page.curr = 1;
                    options.where.workshopCode = $("#selWorkshops").val().trim();
                    options.where.lineId = parseInt($("#selLines").val().trim());
                    var rangeTime = $("#txtRangeTime").val();
                    var startTime = rangeTime.split('至')[0].trim(),
                        endTime = rangeTime.split('至')[1].trim();
                    options.where.startTime = startTime;
                    options.where.endTime = endTime;
                    $("#btnExport").attr("href", "/Report/ExportQualityReports?workshopCode=" + options.where.workshopCode + "&lineId=" + options.where.lineId + "&startTime=" + startTime + "&endTime=" + endTime);

                    if (table.index <= 0) {
                        table.render(options);
                    } else {
                        table.reload("table", options);
                    }
                }
            });
        }
    </script>
}
